using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using WpfApp1.Services;
using WpfApp1.ViewModels;
using WpfApp1.Models;

namespace WpfApp1.Views;

public partial class StudentDashboard : Window
{
    private readonly StudentDashboardViewModel _viewModel;
    
    public StudentDashboard(string studentNumber, IStudentService studentService, 
        ICourseService courseService, ICourseSelectService courseSelectService)
    {
        InitializeComponent();
        _viewModel = new StudentDashboardViewModel(studentNumber, studentService, 
            courseService, courseSelectService);
        DataContext = _viewModel;
        // 只加载学生基本信息
        _viewModel.LoadCurrentStudent();
    }

    //保存学生信息
    private void SaveStudentInfo_Click(object sender, RoutedEventArgs e)
    {
        _viewModel.UpdateStudentInfo(_viewModel.CurrentStudent);
    }

    //课程按钮点击
    private void SearchCourse_Click(object sender, RoutedEventArgs e)
    {
        _viewModel.SearchCourse(CourseNumberTextBox.Text);
    }

    //显示所有课程
    private void SearchAllCourses_Click(object sender, RoutedEventArgs e)
    {
        _viewModel.LoadAllCourses();
    }
    
    //选课按钮点击
    private void SelectCourse_Click(object sender, RoutedEventArgs e)
    {
        if (sender is Button button && button.Tag is string courseNumber)
        {
            _viewModel.SelectCourse(courseNumber);
        }
    }

    //关闭窗口
    private void CloseButton_Click(object sender, RoutedEventArgs e)
    {
        this.Close();
    }

    //窗口移动
    private void Window_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (e.ChangedButton == MouseButton.Left)
        {
            this.DragMove();
        }
    }
}